package com.anxin.service.impl;

import com.anxin.entity.DoctorInfo;
import com.anxin.mapper.DoctorInfoMapper;
import com.anxin.service.DoctorInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class DoctorInfoServiceImpl extends ServiceImpl<DoctorInfoMapper, DoctorInfo> implements DoctorInfoService {

    @Override
    public List<DoctorInfo> getDoctorsByDepartment(String departmentId) {
        return this.list(new LambdaQueryWrapper<DoctorInfo>()
                .eq(DoctorInfo::getDepartmentId, departmentId)
                .eq(DoctorInfo::getStatus, 1));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateDoctorStatus(String doctorId, Integer status) {
        DoctorInfo doctor = new DoctorInfo();
        doctor.setId(doctorId);
        doctor.setStatus(status);
        this.updateById(doctor);
    }

    @Override
    public DoctorInfo getByUserId(String userId) {
        return this.getOne(new LambdaQueryWrapper<DoctorInfo>()
                .eq(DoctorInfo::getUserId, userId));
    }
} 